package wz

import (
	"fmt"
	"github.com/go-resty/resty/v2"
	"navi-mumbai/common/xerr"
	"net/http"
)

type GuestAuthReq struct {
	Currency string `json:"currency"` // USD GOLD
	Lang     string `json:"lang"`     // en
}

type GuestAuthData struct {
	Token    string `json:"Token"`
	Username string `json:"Username"`
	UserId   int64  `json:"UserId"`
}

type GuestAuthResp struct {
	Code int           `json:"code"`
	Data GuestAuthData `json:"data"` // G端的用户登录Token，最大128字节
}

const tourAuthURI = "wzgames/tour/sample"

func (r *HttpClient) GuestAuth(req *GuestAuthReq) (resp *GuestAuthResp, err error) {
	resp = &GuestAuthResp{}
	var rsp *resty.Response

	rsp, err = r.cli.R().SetHeader("Accept", "application/json").SetQueryParams(map[string]string{
		"operator": r.GuestId,
		"currency": req.Currency,
		"lang":     req.Lang,
	}).SetResult(resp).SetError(resp).Post(r.DemoHost + tourAuthURI)
	if err != nil {
		return
	}
	if rsp.IsError() {
		err = xerr.NewGrpcErrCodeMsg(xerr.ThirdPartRequestError, rsp.Status())
		return
	}
	if resp.Code != http.StatusOK {
		err = xerr.NewGrpcErrCodeMsg(xerr.ThirdPartRequestError, fmt.Sprintf("code:%d", resp.Code))
		return
	}

	return
}
